<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let arr = [1, 2];
            // console.log(arr.push(1, 2, 3)); // 5
            // console.log(arr); // [1,2,1,2,3]
            let obj = { name: 'zs' };
            // obj.push(3);

            Array.prototype.myPush = function () {
                for (let i = 0; i < arguments.length; i++) {
                    // this就是调用该方法的数组arr,
                    // 数组当前最后一项的索引为 this.length - 1，再往后面加索引就为this.length
                    this[this.length] = arguments[i];
                }
                return this.length;
            };
            console.log(obj.myPush(1, 2, 3)); // 5
            console.log(arr); //  [1,2,1,2,3]
        </script>
    </body>
</html>
